﻿using Microsoft.AspNetCore.Http;
using System.Text;

namespace wsess
{
    public class SessionHelpler
    {
        private IHttpContextAccessor _httpContextAccessor;
        private ISession _session;
        public SessionHelpler(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
            _session = _httpContextAccessor.HttpContext.Session;
        }

        public void SetSession(string key,string value)
        {
            _session.Set(key, Encoding.Default.GetBytes(value));
        }
        public string GetSession(string key)
        {
            if (_session.TryGetValue(key, out byte[] value))
            {
                return Encoding.Default.GetString(value);
            }
            return "";
        }
    }
}
